<template>
	<view class="c-wrap">
		<view class="g-nav" :style="[customstyle]">
			<view class="g-navItem" :class="{active: navindex == index}" v-for="(item, index) in navlist" :key="index"
				@click="$emit('click', index)">
				{{item.name}}
			</view>
			<view class="g-navBorder" :style="{left: `${borderLeft}rpx`}"></view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			navlist: {
				type: Array,
				default () {
					return []
				}
			},
			navindex: {
				type: Number,
				default: 0
			},
			customstyle: {
				type: Object,
				default () {
					return {
						backgroundColor: '#fff'
					}
				}
			}
		},
		computed: {
			borderLeft() {
				let len = this.navlist.length
				let itemW = 750 / len
				return (itemW - 60) / 2 + this.navindex * itemW
			}
		},
		data() {
			return {

			}
		},
		onLoad(options) {

		},
		methods: {

		}
	}
</script>

<style scoped lang="scss">
	.g-nav {
		position: relative;
		display: flex;
		height: 90rpx;
	}

	.g-navItem {
		flex: 1;
		line-height: 90rpx;
		text-align: center;
		color: #808080;

		&.active {
			font-weight: bold;
			color: $g-main-color;
		}
	}

	.g-navBorder {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 60rpx;
		height: 4rpx;
		border-radius: 2rpx;
		transition: left 0.3s;
		background-color: $g-main-color;
	}
</style>
